package com.service.impl;

import com.dao.StudentDAO;
import com.entity.Student;
import com.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("studentService")
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDAO studentDAO;
    @Override
    public Map selectAll(Integer page, Integer limit, String studentName) {
            if (studentName!=null&&!studentName.equals("")){
                studentName="%"+studentName+"%";
            }else {
                studentName=null;
            }
            Integer offset=(page-1)*limit;
            List<Student> list=studentDAO.selectAll(offset,limit,studentName);
            Integer count=studentDAO.selectCount(studentName);
            Map map=new HashMap();
            map.put("data",list);
            map.put("count",count);
            map.put("code",0);
            map.put("msg","");
            return map;
    }
    @Override
    public Student selectOneById(Integer studentId) {
        return studentDAO.selectOneById(studentId);
    }

    @Override
    public Map update(Student student) {
        int count = studentDAO.update(student);
        Map map = new HashMap();
        if(count>0){
            map.put("isUpdate",true);
        }else{
            map.put("isUpdate",false);
        }
        return map;
    }

    @Override
    public Map multiDelete(int[] ids) {
        int count =studentDAO.multiDelete(ids);
        Map map = new HashMap();
        if(count>0){
            map.put("isDelete","删除成功");
        }else{
            map.put("isDelete","删除失败");
        }
        return map;
    }
}
